package com.netcracker.studportal.server.model;
import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.json.simple.JSONObject;

@Entity
@Table(name = "Materials")
public class Material implements Serializable {
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "my_seq_gen")
    @SequenceGenerator(name = "my_seq_gen", sequenceName = "seq_mater")
	@Column(name= "material_id")
	private Long material_id;
	
	@ManyToOne
	@JoinColumn(name = "exam_id")
	private Exam exam;
	
	@Column(name= "name")
	private String material_name;
	
	@Column(name= "path")
	private String material_path;
	
	//getters
	
	public Long getId(){return this.material_id;}
	
	public Exam getExam(){return this.exam;}
	
	public String getName(){return this.material_name;}
	
	public String getPath(){return this.material_path;}
	
	//setters
	
	public void setId(Long id) {this.material_id=id;}
	
	public void setExam(Exam exam) {this.exam = exam;}
	
	public void setName(String name) {this.material_name = name;}
	
	public void setPath(String path) {this.material_path = path;}
	
	public JSONObject kJSON(){
		JSONObject obj=new JSONObject();
		if(this.material_id!=null) obj.put("material_id", this.material_id.toString());
		if(this.exam!=null){
		if(this.exam.getId()!=null) obj.put("exam_id", this.exam.getId().toString());
		}
		obj.put("material_name", this.material_name);
		//obj.put("material_path", this.material_path);
		
		return obj;		
	}
	
}
